//
// Created by shaowenhan on 2020/4/27.
//

#ifndef MDVRP_READINSTANCE_H
#define MDVRP_READINSTANCE_H
#include "DefineProblemType.h"
#if defined(MDVRP) or defined(MDOVRP)
#include <string>
#include <climits>
#include "Instance.h"
#include "ReadInstanceWrapper.h"
#include "Log.h"

class ReadMDVRPInstance
{
private:
    ReadInstanceWrapper m_readInstanceWrapper;
    int m_size;
    vector<char> m_separators;

    vector<double> m_xs;
    vector<double> m_ys;
    Instance m_instance;

    void allocateSpaceForMembers();
    void readProblemTypeVehicleAndNodeNumber();
    void readDurationTimeAndLoad();
    void readNode(int nodeIndex);
    void readNodes();
    void computeDistances();
    double powOfNum(double num);
public:
    explicit ReadMDVRPInstance(const string& filename): m_readInstanceWrapper(filename), m_separators({' ', '\n', '\r'}){
        m_instance.instanceName = filename;
        readProblemTypeVehicleAndNodeNumber();
        allocateSpaceForMembers();
        readDurationTimeAndLoad();
        readNodes();
        computeDistances();
    }
    Instance obtainInstance() const;
};

#endif
#endif //MDVRP_READINSTANCE_H
